<?php
class Block_Admin_User_View_Item
    extends Block_Core_Form_Abstract
{
    protected $_formName = 'user_view';

    protected $_formId = 'admin_user_view';

    protected $_jsName = 'admin_user_view';

    protected function _prepareForm()
    {
        $fieldset = new Block_Core_Form_Fieldset_Abstract();
        $fieldset->setData(array('label'=>'Account Informaton','title'=>'Account Informaton','view'=>'open'));

        $fieldset->addField(array(
            'type' => 'hidden',
            'name' => 'user[id]',
            'value'=> $this->getId(),
        ));

        $fieldset->addField(array(
            'title'=>'User Name',
            'label'=>'User Name',
            'type' =>'text',
            'value'=> $this->getName(),
            'name' =>'user[name]',
            'required'=>true,
            'comment'=>'Admin user name',
        ));

        $fieldset->addField(array(
            'title'=>'Email',
            'label'=>'Email',
            'type' =>'text',
            'name' =>'user[email]',
            'value'=> $this->getEmail(),
            'required'=>true,
            'comment'=>'Admin user email',
        ));

        $fieldset->addField(array(
            'title'=>'Firstname',
            'label'=>'Firstname',
            'type' =>'text',
            'value'=> $this->getFirstname(),
            'name' =>'user[firstname]',
        ));

        $fieldset->addField(array(
            'title'=>'Lastname',
            'label'=>'Lastname',
            'value'=> $this->getLastname(),
            'type' =>'text',
            'name' =>'user[lastname]',
        ));
        
//        $fieldset->addField(array(
//            'title'=>'Tree',
//            'label'=>'Tree',
//            'type' =>'tree',
//            'params'=> $this->getTestTree(),
//            'name' =>'user[tree]',
//            'id'=>'test_tree',
//            'required'=>true,
//        ));

        $this->addFieldset($fieldset);

        $fieldset = new Block_Core_Form_Fieldset_Abstract();
        $fieldset->setData(array('label'=>'Password Informaton','title'=>'Password Informaton','view'=>'close'));



        if($this->getId()) {
            $fieldset->addField(array(
                'title'=>'Set new Password',
                'label'=>'Set new Password',
                'type' =>'checkbox',
                'name' =>'user[set_password]',
            ));

            $fieldset->addField(array(
                'title'=>'Current Password',
                'label'=>'Confirmation',
                'type' =>'password',
                'name' =>'user[current_password]',
            ));

            $fieldset->addField(array(
                'title'=>'New Password',
                'label'=>'New Password',
                'type' =>'password',
                'name' =>'user[new_password]',
            ));

            $fieldset->addField(array(
                'title'=>'New Password Confirmation',
                'label'=>'New Password Confirmation',
                'type' =>'password',
                'name' =>'user[new_confirmation]',
            ));
        } else {
            $fieldset->addField(array(
                'title'=>'Password',
                'label'=>'Password',
                'type' =>'password',
                'name' =>'user[password]',
            ));

            $fieldset->addField(array(
                'title'=>'Password Confirmation',
                'label'=>'Confirmation',
                'type' =>'password',
                'name' =>'user[confirmation]',
            ));
        }

        $this->addFieldset($fieldset);

        return parent::_prepareForm();

    }

    protected function _prepareData()
    {
        /* @var $controller Zend_Controller_Front */
        $controller = Zend_Controller_Front::getInstance();
        $item = $controller->getRequest()->getParam('item',null);

        if($item) {
            $model = new Model_Admin_User_Admin();
            $model->load($item);

            foreach ($model->getData() as $key=>$value) {
                $this->setData($key,$value);
            }
        }

        return parent::_prepareData();
    }

    public function getFormatedNameValue($name)
    {
        $name = substr($name, 5);
        $name = substr($name, 0, -1);
        return $name;
    }

//    public function getTestTree()
//    {
//        $params = array(
//            array(
//                'label'=>'All',
//                'value'=>'all',
//                'chields' => array(
//                    array(
//                        'label'=>'Node 1',
//                        'value'=>'node_1',
//                    ),
//                    array(
//                        'label'=>'Node 2',
//                        'value'=>'node_2',
//                        'chields' => array(
//                            array(
//                                'label'=>'Node 1',
//                                'value'=>'node_1',
//                            ),
//                            array(
//                                'label'=>'Node 2',
//                                'value'=>'node_2',
//                            ),
//                            array(
//                                'label'=>'Node 3',
//                                'value'=>'node_3',
//                            ),
//                        )
//                    ),
//                    array(
//                        'label'=>'Node 3',
//                        'value'=>'node_3',
//                    ),
//                )
//            ),
//        );
//        return $params;
//    }
}